/**
 * @author  : ZhiBing.Li
 * @date    : 2013-10-15下午01:15:58
 */
package flexcomm.controls.checkboxdg
{
	import flash.events.Event;
	
	import spark.components.CheckBox;
	import spark.components.gridClasses.GridItemRenderer;
	
	public class CheckBoxHeader extends GridItemRenderer
	{
		private var _checkBox:CheckBox;
		
		public function CheckBoxHeader()
		{
			super();
		}
		
		override public function set data(value:Object):void
		{
			
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			if(!_checkBox)
			{
				_checkBox = new CheckBox();
				_checkBox.toolTip = "全选";
				_checkBox.addEventListener(Event.CHANGE,onChangeHandler);
				addElement(_checkBox);
			}
		}
		
		override protected function updateDisplayList(w:Number, h:Number):void
		{
			super.updateDisplayList(w,h);
			
			//设置checkBox的X
			var ckbX:Number = (w - _checkBox.width) / 2;
			//设置checkBox的Y
			var ckbY:Number = (h - _checkBox.height) / 2;
			//设置checkBox的坐标及大小
			_checkBox.move(ckbX,ckbY);
		}
		
		protected function onChangeHandler(event:Event):void
		{
			var eveObj:CheckBoxEvent = new CheckBoxEvent(CheckBoxEvent.CHANGE);
			eveObj.selected = _checkBox.selected;
			CheckBoxDataGrid(this.owner).dispatchEvent(eveObj);
		}
	}
}